﻿@model notice
@{
    ViewData["Title"] = "发布公告";
    var m = Model;
}

<div class="row">
    <form id="ajaxForm" enctype="multipart/form-data" class="form-horizontal">
        <input type="hidden" name="id" value="@m.id.ToString()" />
        <div class="container-fluid">
            <div class="row form-group">
                <label class="control-label col-md-2">公告内容</label>
                <div id="editor" class="col-md-10">
                    @{
                        if (string.IsNullOrWhiteSpace(m.content))
                        {
                            <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
                        }
                        else
                        {
                            @Html.Raw(m.content);
                        }
                    }
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">是否显示</label>
                <div class="col-md-10">
                    <input class="i-checks" name="show" id="isShow" type="checkbox" value="true" @(m.is_show ? "checked" : string.Empty) />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">修改人</label>
                <div class="col-md-10">
                    <input class="form-control" name="show" id="isShow" type="text" value="@m.user_name" readonly />
                </div>
            </div>
            <div class="row form-group">
                <label class="control-label col-md-2">修改时间</label>
                <div class="col-md-10">
                    <input class="form-control" name="show" id="isShow" type="text" value="@m.last_update.ToLocalTime().ToString()" readonly />
                </div>
            </div>

            <div class="row form-group">
                <div class="col-md-6 col-md-offset-2">
                    <button type="button" class="btn btn-primary" onclick="SaveNotice()">保存</button>
                </div>
            </div>
        </div>
    </form>
</div>

@section scripts{
    <script type="text/javascript">
        var E = window.wangEditor
        var editor = new E('#editor')
        // 或者 var editor = new E( document.getElementById('editor') )
        editor.customConfig.uploadImgShowBase64 = true
        editor.create();

        E.fullscreen.init(editor);
        E.viewSource.init(editor);

        function SaveNotice() {
            $("#ajaxForm").ajaxSubmit({
                type: 'post',
                url: '@Url.Action(nameof(ArticleController.UpdateNotice), "Article")',
                data: {
                    content: editor.txt.html()
                },  // data是作为额外提交的表单数据
                success: function (e) {
                    if (e.msg == 'ok') {
                        utils.ShowSuccess(e.data, function () {
                            location.reload(true);
                        });
                    }
                },
                error: function (e) {
                    utils.ShowError(e.data);
                }
            });
        }
    </script>
}